Skip to content

Instantly share code, notes, and snippets.

View arshpreetsingh's full-sized avatar
💭
Get it Done! "Engineer"

Arshpreet Singh arshpreetsingh

💭
Get it Done! "Engineer"
View GitHub Profile
@arshpreetsingh
arshpreetsingh / Gmail_oauth2.py
Last active August 29, 2015 14:23
Wana get Idea what script is doing just concentrate on Main function. Python-social-auth returns Access_token(y29.xxxxx)oauth2.py made only to wok for auth_token and Email, Basically It generates the auth_string, Which help to IMAP login for Gmail using Oauth2. main idea is got from http://google-mail-oauth2-tools.googlecode.com/svn/trunk/python…
#!/usr/bin/python
#
# Copyright 2012 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
from imaplib import IMAP4_SSL
from datetime import date, timedelta, datetime
from time import mktime
from email.utils import parsedate
import email
import pygal
address = 'myid@gmail.com'
password = 'my gmail password'
'xrd55u92qftq'
import requests
import os
os.chdir('/home/metal-machine/hello/')
pdf_files = os.listdir(".")
for pdf_file in pdf_files:
print pdf_file
files = {'f': (pdf_file, open(pdf_file, 'rb'))}
#response = requests.post("https://pdftables.com/api?key=xrd55u92qftq&format=xlsx-single", files=files)
@arshpreetsingh
arshpreetsingh / matplot.py
Created December 12, 2016 00:12
Matplotlib playing with interpolation
from scipy.interpolate import interp1d
x= [1,2,3,4]
y = [1,2,12,25]
#x2 = np.arange(4,20)
#x2=[4,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]
y21 = np.arange(0,9,100)
x2 = [4,4.5,4.8,5.5,6,9,10,11,12,13,14,15,18,18.5,19,19.5,21]
y2=[1,2,4,6,7,9,9,9,9,9,9,9,7,6,4,2,1]
#x = np.linspace(0, 10, num=11, endpoint=True)
#y = np.cos(-x**2/9.0)
def getDiff(symbol,hours):
""" function to calculate Daily Returns
ohlc4 = (open+high+low+close)/4
"""
delta = ohlc4_today(symbol)-ohlc_yesterday(hours)
return delta/ohlc_yesterday(hours)
from sklearn.qda import QDA
#from sklearn.ensemble import RandomForestRegressor
from sklearn import preprocessing
import numpy as np
import pandas as pd
def initialize(context):
context.assets = sid(8554) # Trade SPY
context.model = QDA()
context.lookback = 5 # Look back
# Use the previous 10 bars' movements to predict the next movement.
# Use a random forest classifier. More here: http://scikit-learn.org/stable/user_guide.html
from sklearn.ensemble import RandomForestRegressor
import numpy as np
def initialize(context):
context.security = sid(8554) # Trade SPY
context.model = RandomForestRegressor()
# Use the previous 10 bars' movements to predict the next movement.
# Use a random forest classifier. More here: http://scikit-learn.org/stable/user_guide.html
#from sklearn.ensemble import RandomForestRegressor
import numpy as np
from sklearn.linear_model import LogisticRegression
def initialize(context):
context.security = sid(8554) # Trade SPY
context.model = LogisticRegression()
# Use the previous 10 bars' movements to predict the next movement.
# Use a random forest classifier. More here: http://scikit-learn.org/stable/user_guide.html
#from sklearn.ensemble import RandomForestRegressor
import numpy as np
from sklearn.qda import QDA
def initialize(context):
context.security = sid(8554) # Trade SPY
"""
Important notes about model
Training Machine-Learning model is trained every Monday (I found that if I train my model every-day it shows less returns)
Trading is happening after each 10 minutes
Machine_learning Model:
I am using two independent Features: '5 minutes price change' and '15 minutes price change'