Created
August 3, 2020 01:32
-
-
Save shashankvemuri/de7592e17e35ddcd68cce2aa70359594 to your computer and use it in GitHub Desktop.
End of code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prices = df['Adj Close'].tolist() | |
first_price = prices[0] | |
new_col = [current_price, current_price, current_price, current_price, current_price, current_price] | |
if hold > 0: | |
holding = [['Buy and Hold', hold, 1, first_price, np.nan, hold, np.nan, hold, np.nan, np.inf, 1]] | |
else: | |
holding = [['Buy and Hold', hold, 1, first_price, np.nan, np.nan, hold, np.nan, hold, 0, 0]] | |
dataframe = pd.DataFrame(list(zip(signals, change, num_of_trades, last_buy, last_sell, average_gain, average_loss, max_return, max_loss, gain_loss, success_rate)), columns =['Strategy', 'Total Return' ,'Number of Trades', 'Last Buy', 'Last Sell' ,'Average Gain', 'Average Loss', 'Max Return', 'Max Loss', 'Gain/Loss Ratio', 'Success Rate']) | |
dataframe = dataframe.append(pd.DataFrame(holding, columns =['Strategy', 'Total Return' ,'Number of Trades', 'Last Buy', 'Last Sell', 'Average Gain', 'Average Loss', 'Max Return', 'Max Loss', 'Gain/Loss Ratio', 'Success Rate']),ignore_index=True) | |
dataframe = dataframe.set_index('Strategy') | |
dataframe = dataframe.sort_values('Total Return', ascending=False) | |
dataframe = dataframe.round(2) | |
print ('\nFull Statistics: ') | |
print (dataframe) | |
print ('\nCurrent Price: ' + str(current_price)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment