<jupyter_start><jupyter_text>Double 7's (Short Term Trading Strategies that Work)    1. The SPY is above its 200-day moving average    2. The SPY closes at a X-day low, buy some shares.       If it falls further, buy some more, etc...    3. If the SPY closes at a X-day high, sell your entire long position.        (Scaling in; compare regular trade log vs merged trade log)<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt
import datetime
from talib.abstract import *

import pinkfish as pf
import strategy

# format price data
pd.options.display.float_format = '{:0.2f}'.format

%matplotlib inline
# set size of inline plots
'''note: rcParams can't be in same cell as import matplotlib
   or %matplotlib inline
   
   %matplotlib notebook: will lead to interactive plots embedded within
   the notebook, you can zoom and resize the figure
   
   %matplotlib inline: only draw static images in the notebook
'''
plt.rcParams["figure.figsize"] = (10, 7)<jupyter_output><empty_output><jupyter_text>Some global data<jupyter_code>capital = 10000
start = datetime.datetime(2000, 1, 1)
end = datetime.datetime.now()<jupyter_output><empty_output><jupyter_text>Define symbols<jupyter_code>symbols = ['SPY', 'SPY_merged']<jupyter_output><empty_output><jupyter_text>Define high low trade periods<jupyter_code>period = 8<jupyter_output><empty_output><jupyter_text>Define max number of positions to scale into<jupyter_code>max_positions = 4<jupyter_output><empty_output><jupyter_text>Run Strategy<jupyter_code>merge_trades = False
strategies = pd.Series(dtype=object)
for symbol in symbols:
    strategies[symbol] = strategy.Strategy(symbols[0], capital, start, end,
                                           period=period,max_positions=max_positions)
    strategies[symbol].run()
    _, strategies[symbol].tlog, strategies[symbol].dbal = strategies[symbol].get_logs(merge_trades)
    strategies[symbol].stats = strategies[symbol].get_stats()
    merge_trades = True<jupyter_output><empty_output><jupyter_text>Summarize results<jupyter_code>metrics = strategies[symbol].stats.index

df = strategy.summary(strategies, metrics)
pd.set_option('display.max_columns', len(df.columns))
pd.set_option('display.max_rows', len(df))
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.09823008849557523, 'fraction_numerical': 0.011504424778761062, 'mean_word_length': 5.298050139275766, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '251584', 'license': 'MIT', 'n_tokens_mistral': 746, 'n_tokens_neox': 714, 'n_words': 190, 'path': 'examples/merge-trades/strategy.ipynb', 'repo_name': 'tombohub/pinkfish', 'size': '2260'}