How to use index_strategy method in pandera

Best Python code snippet using pandera_python

Replicate_Figure1.py

Source:Replicate_Figure1.py Github

copy

Full Screen

1import numpy as np2import pandas as pd3import matplotlib.pyplot as plt4import strategymodels5from Functions.set_Beta_prior import set_priors6from Functions.update_strategy_posterior_probability import update_strategy_posterior_probability7from Functions.Summaries_of_Beta_distribution import summaries_of_Beta_Distribution8from Functions.plotSessionStructure import plotSessionStructure9from Functions.interpolate_null_trials import interpolate_null_trials10# initiate TestData variable so that rat 2 testdata can be loaded11TestData = pd.read_csv('data.csv')12# choose strategies to evaluate: subset shown in Figure 113strategies = ['go_left','go_right','go_cued','win_stay_spatial','lose_shift_cued','lose_shift_spatial']14# set prior15prior_type = 'Uniform' #set prior type16decay_rate = 0.917[alpha0, beta0] = set_priors(prior_type) # define priors18#%% initialise storage19Output_collection = {} # empty dict in which to store dataframes20event_totals = {} # empty dict to store totals of events for each strategy21# initialise dataframes22for index_strategy in range(len(strategies)):23 Output_collection[strategies[index_strategy]] = pd.DataFrame(columns = ['Alpha', 'Beta','MAPprobability', 'Precision','Alpha_interpolated', 'Beta_interpolated','MAPprobability_interpolated', 'Precision_interpolated']) # empty Dataframe to input data into24 event_totals[strategies[index_strategy]] = {}; # create empty dict for this strategy25 event_totals[strategies[index_strategy]]['success_total'] = 0;26 event_totals[strategies[index_strategy]]['failure_total'] = 0;27#%%28for trial in range(len(TestData)):29 30 rows_of_data = TestData.iloc[0:trial+1] # select all rows of data up to the curren trial; is trial+1 as dataframe includes colu 31 32 #%% 33 for index_strategy in range(len(strategies)):34 # run current strategy model on data up to current trial 35 strategy_fcn = getattr(strategymodels,strategies[index_strategy]) # dynamically assign string as function to be called36 trial_type = strategy_fcn(rows_of_data) #call currently assigned function37 38 # update probability of strategy39 [event_totals[strategies[index_strategy]]['success_total'], event_totals[strategies[index_strategy]]['failure_total'], Alpha, Beta] \40 = update_strategy_posterior_probability(trial_type, decay_rate,event_totals[strategies[index_strategy]]['success_total'], event_totals[strategies[index_strategy]]['failure_total'],alpha0, beta0)41 42 MAPprobability = summaries_of_Beta_Distribution(Alpha, Beta, 'MAP')43 precision = summaries_of_Beta_Distribution(Alpha, Beta, 'precision')44 45 46 #%% interpolate null trials47 this_trials_data= {'Alpha':Alpha, 'Beta':Beta, 'MAPprobability':MAPprobability, 'Precision':precision} # create dict of current data to pass48 if trial > 0:49 previous_trials_data = Output_collection[strategies[index_strategy]].iloc[trial-1] 50 else:51 previous_trials_data = Output_collection[strategies[index_strategy]] # pass empty dataframe52 53 new_row_of_data = interpolate_null_trials(this_trials_data,previous_trials_data,alpha0,beta0)54 55 # store results - dynamically-defined dataframe...56 new_df= pd.DataFrame([new_row_of_data]) # have to convert to dataframe to use concat!!57 Output_collection[strategies[index_strategy]] = pd.concat([Output_collection[strategies[index_strategy]], new_df], ignore_index=True) # add new row to dataframe58 59 60#%% plot results61no_Trials = np.size(TestData.TrialIndex)62# plotting time series of MAPprobability for Rule Strategies63plt.figure(figsize=(10, 5))64plt.plot(Output_collection['go_left'].MAPprobability, linewidth=0.75) # plots the time series65plt.plot(Output_collection['go_right'].MAPprobability, linewidth=0.75, color=(0.4, 0.8, 0.5)) # plots the time series66plt.plot(Output_collection['go_cued'].MAPprobability, linewidth=0.75, color=(0.8,0.6,0.5)) # plots the time series67plt.axis([0, no_Trials, 0, 1.25]) # establishes axis limits 68plt.xlabel('Trials'), plt.ylabel('P(Strategy)') # labelling the axis69plt.axhline(y=0.5, color='darkgrey', linewidth=0.75, label="Chance") # shows the line at which Chance is exceeded70plotSessionStructure(TestData)71plt.show() 72# plotting Precision for the same three strategies (precision identical for go_left and go_right)73plt.figure(figsize=(10, 5))74plt.plot(Output_collection['go_left'].Precision, linewidth=0.75) # plots the time series75plt.plot(Output_collection['go_cued'].Precision, linewidth=0.75, color=(0.8,0.6,0.5)) # plots the time series76plt.xlabel('Trials'), plt.ylabel('Precision') # labelling the axis77plt.show() 78 79# plotting MAP probability for some exploratory strategies - use interpolated values80plt.figure(figsize=(10, 5))81plt.plot(Output_collection['lose_shift_cued'].MAPprobability_interpolated, linewidth=0.75, color=(1, 0.1, 0.6)) # plots the time series82plt.plot(Output_collection['lose_shift_spatial'].MAPprobability_interpolated, linewidth=0.75, color=(0.8, 0.6, 0.5)) # plots the time series83plt.plot(Output_collection['win_stay_spatial'].MAPprobability_interpolated, linewidth=0.75, color=(0.4,0.8,0.5)) # plots the time series84plt.axis([0, no_Trials, 0, 1.25]) # establishes axis limits 85plt.xlabel('Trials'), plt.ylabel('P(Strategy)') # labelling the axis86plt.axhline(y=0.5, color='darkgrey', linewidth=0.75, label="Chance") # shows the line at which Chance is exceeded87plotSessionStructure(TestData)...

Full Screen

Full Screen

today_3strategy_signal.py

Source:today_3strategy_signal.py Github

copy

Full Screen

1#-*-coding:UTF-8-*-2import datetime3from Models.Closed_Price_Prediction_model import arbitrary_prediction4from Strategys.INDEX_STRATEGY.CYB import CYB5from Strategys.INDEX_STRATEGY.Gold_ETF import GOLD_ETF6from Strategys.INDEX_STRATEGY.NSDK import NSDK7from Strategys.INDEX_STRATEGY.hs_300_strategy import hs_300_strategy8from Strategys.INDEX_STRATEGY.petro_ETF import PETRO_ETF9from pitcher import get_his_data10today = datetime.datetime.today()-datetime.timedelta(1)11yesterday = str(today)[0:10]12def tree_predict(df):13 xx = arbitrary_prediction(df)14 return [xx.one_day_gradient_change()]15start = '2015-10-10'16gold_index = get_his_data('159934',start=start,ma=[4,5,12,13,16,18,20,30,60,120,14],index=True)17gold_index = tree_predict(gold_index)18petro_index = get_his_data('162411',ma=[4,5,12,13,16,18,20,30,60,120,14],start=start,index=True)19petro_index = tree_predict(petro_index)20hs300_index = get_his_data('000300',ma = [5,12,13,16,18,20,30,60,120,14],start=start,index=True)21hs300_index = tree_predict(hs300_index)22cyb = get_his_data('399006',ma = [4,5,12,13,16,18,20,30,60,120,14,10],start=start,index=True)23cyb = tree_predict(cyb)24NSD_ETF = get_his_data('513100',ma=[3,60,120,250],start=start,index=True)25NSD_ETF = tree_predict(NSD_ETF)26open('todays_results.csv','w')27print('Processing Gold_Index')28open('todays_results.csv', 'a').write('GOLD_Prediction')29for i in gold_index:30 gold = GOLD_ETF(i)31 gold = gold.today_signal()32 gold.to_csv('todays_results.csv',mode='a')33 open('todays_results.csv', 'a').write('\n')34open('todays_results.csv','a').write('\n')35print('Processing Petro_index')36open('todays_results.csv', 'a').write('OIL_Prediction')37for i in petro_index:38 gold = PETRO_ETF(i)39 gold = gold.today_signal()40 gold.to_csv('todays_results.csv',mode='a')41 open('todays_results.csv', 'a').write('\n')42open('todays_results.csv','a').write('\n')43print('Processing hs300_index')44open('todays_results.csv', 'a').write('hs300_Prediction')45for i in hs300_index:46 gold = hs_300_strategy(i)47 gold = gold.today_signal()48 gold.to_csv('todays_results.csv',mode='a')49 open('todays_results.csv', 'a').write('\n')50open('todays_results.csv','a').write('\n')51print('Processing cyb')52open('todays_results.csv', 'a').write('CYB_prediction')53for i in cyb:54 gold = CYB(i)55 gold = gold.today_signal()56 gold.to_csv('todays_results.csv',mode='a')57 open('todays_results.csv', 'a').write('\n')58open('todays_results.csv','a').write('\n')59print('Processing NSD_index')60open('todays_results.csv', 'a').write('NASDAQ_Prediction')61for i in NSD_ETF:62 gold = NSDK(i)63 gold = gold.today_signal()64 gold.to_csv('todays_results.csv',mode='a')65 open('todays_results.csv', 'a').write('\n')66open('todays_results.csv','a').write('\n')67#print('黄金今日买卖信号: ')68#gold.today_signal()69#print('石油今日买卖信号: ')70#petro.today_signal()71#print('沪深300今日买卖信号: ')72#hs300#.today_signal()73#print('创业板今日买卖信号: ')...

Full Screen

Full Screen

test_concept_index.py

Source:test_concept_index.py Github

copy

Full Screen

1import unittest2import datetime3import unittest4from strategy.strategy_index_calculator import IndexCalculatorStategy5from jqdemo.offline_stock_action import OfflineStockAction6from jqdemo.stock_action import StockAction7from config.config import *8class TestConceptIndex(unittest.TestCase):9 def __init__(self, method_name):10 unittest.TestCase.__init__(self, method_name)11 self.index_strategy = IndexCalculatorStategy()12 self.offline_stock_action = OfflineStockAction()13 def test_concept_index(self):14 self.index_strategy.calculate_concept_index('GN086')15 pass16if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pandera automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful