my net house

WAHEGURU….!

Tag Archives: python

TPOT Python Example to Build Pipeline for AAPL

This is  just first Quick and Fast Post.

TPOT Research  Paper: https://arxiv.org/pdf/1702.01780.pdf


import datetime
import numpy as np
import pandas as pd
import sklearn
from pandas_datareader import data as read_data
from tpot import TPOTClassifier
from sklearn.model_selection import train_test_split

apple_data = read_data.get_data_yahoo("AAPL")
df = pd.DataFrame(index=apple_data.index)
df['price']=apple_data.Open
df['daily_returns']=df['price'].pct_change().fillna(0.0001)
df['multiple_day_returns'] =  df['price'].pct_change(3)
df['rolling_mean'] = df['daily_returns'].rolling(window = 4,center=False).mean()

df['time_lagged'] = df['price']-df['price'].shift(-2)

df['direction'] = np.sign(df['daily_returns'])
Y = df['direction']
X=df[['price','daily_returns','multiple_day_returns','rolling_mean']].fillna(0.0001)

X_train, X_test, y_train, y_test = train_test_split(X,Y,train_size=0.75, test_size=0.25)

tpot = TPOTClassifier(generations=50, population_size=50, verbosity=2)
tpot.fit(X_train, y_train)
print(tpot.score(X_test, y_test))
tpot.export('tpot_aapl_pipeline.py')

The Python file It returned: Which is real Code one can use to Create Trading Strategy. TPOT helped to Selected Algorithms and Value of It’s features. right now we have only provided ‘price’,’daily_returns’,’multiple_day_returns’,’rolling_mean’ to predict Target. One can use multiple features and implement as per the requirement.


import numpy as np
import pandas as pd
from sklearn.ensemble import GradientBoostingClassifier
from sklearn.model_selection import train_test_split

# NOTE: Make sure that the class is labeled 'target' in the data file
tpot_data = pd.read_csv('PATH/TO/DATA/FILE', sep='COLUMN_SEPARATOR', dtype=np.float64)
features = tpot_data.drop('target', axis=1).values
training_features, testing_features, training_target, testing_target = \
            train_test_split(features, tpot_data['target'].values, random_state=42)

# Score on the training set was:1.0
exported_pipeline = GradientBoostingClassifier(learning_rate=0.5, max_depth=7, max_features=0.7500000000000001, min_samples_leaf=11, min_samples_split=12, n_estimators=100, subsample=0.7500000000000001)

exported_pipeline.fit(training_features, training_target)
results = exported_pipeline.predict(testing_features)

Learn Python and OOPS

OOPS…..!!
Ok first of all when we think about OOPS we think about class.
yes Class
1.Create Class

class Honey:
name=”Arshpreet”;
#Object for class
meandme=Honey();
#Access variable of class using object
print meandme.name;

#One more object
myandmy = Honey();
#assign new value to variable using object

myandmy.name = “yackity”;
print myandmy.name;
[]
For using function just use object with function name. like meandme.functionname(). so I think we can also use other stuff too in Python class. That’s All

python sikhni hai

HOW to install SymPy on ubuntu —-> A full-featured computer algebra system (CAS)

SymPy is an open source Python library for symbolic mathematics. It aims to become a full-featured computer algebra system (CAS) while keeping the code as simple as possible in order to be comprehensible and easily extensible. SymPy is written entirely in Python and does not require any external libraries.

The full features of sympy can be found here in the official page.. –

</p><p>Main page is at: <a href=”http://sympy.org/” rel=”nofollow“>http://sympy.org/</a&gt; </p><p>

I want to share with you something more than that.here first i will tell you how to install sympy a full featured package as follows

  • gmpy, Cython –> speed improvement
  • Pyglet, Matplotlib –> 2d and 3d plotting
  • IPython –> interactive sessions

gmpy,cython,pyglet,IPython can be used to extend this CAS functionality.Copy the following link in your browser  to download the script for the automation in installation of complete sympy package.just download the script and save it on your desktop and run the script.

http://www.filefactory.com/file/60ewl6ha5dmz/n/arsh_sh

How to run SAGE MATH on ubuntu 11.04

In my six week training i got the project related to sage math..Sage is a free open-source mathematics software system licensed under the GPL. It combines the power of many existing open-source packages into a common Python-based interface. my task was to complete study of sage and writing a python script for sage.

HOW TO INSTALL SAGE
1.)first of all download the sage binary from the link
http://sagemath.org/download-linux.html

2.)choose your mirror for downloading..well i used the following mirror for fast downloading

http://boxen.math.washington.edu/sage/linux/index.html

3.)select your version 32 bit or 64 bit.

4.)after the completion of download you will get a file with the extensions of .tar.lzma.it can be easily extracted in ubuntu linux using the command in terminal
“tar –lzma -xvf sage-*…tar.lzma” command
5.)if you are not so good with terminal then write click on the downloaded file and select extract here.

6.)when the file will be extracted completely open the terminal(alt+ctrl+t) and type following commands

cd /”path of the directory where sage file is located”/
cd /”name of the sage directory”/
if tou are able to run above commands successfully then in the terminal you will get the output like this. i downloaded file in the downloads directory and name of sage file is sage4.7

      arshpreet@mercy-machine:~/Downloads/sage4.7$
    then type “./sage” and you will able to run sage sucessfullly..if then any problem persist than first run command “sudo apt-get install gfortran” and then again again run start sage from terminal using “./sage”,, 🙂
%d bloggers like this: