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 / coucg_db.py
Created July 10, 2017 08:29
CouchBD_Python-Operations
import couchbase.subdocument as SD
from couchbase.bucket import Bucket
# Connecting to DB
cb = Bucket('couchbase:///www', username = 'user_arsh',password='Amber252556!@')
# Creating DB
cb.upsert('55',{'55':[{'text':'text','user_id':'user_id','created_at':'created_at','time':'time'}]}) # only run once
#!/usr/bin/python
# required imports
import requests
class TradeClient(object):
""" Client for tradidng through WebAPI
"""
"""
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'
# 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
# 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
def initialize(context):
context.security = sid(8554) # Trade SPY
context.model = RandomForestRegressor()
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
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)
@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)
'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)