Hi All - I'm new to python and algo trading and was hoping for some feedback on my notebook. Can you take a look and offer any suggestions for improvement? A few items that I'm curious about:
- If the lookback date falls on a non-tradeable day (e.g. holiday), will price data be unavailable or will it grab the last available price? If NaaN, what's an efficient way of grabbing the last available day with price data?
#use these variables to determine price change from today until x period ago
#comment out the period_start variables that are not in use
#Example below is for checking 3 month performance
#set_month = today.month - 3
#period_start = today.replace(month = set_month)
set_month = today.month - 3 #today's month minus 3 months
set_year = today.year
set_day = today.day
#comment out the unused period_start objects -- e.g. if using month, comment out day and year
period_start = today.replace(month = set_month)
#period_start = today.replace(day = set_day)
#period_start = today.replace(year = set_year)
- This seems sloppy -- is there a more efficient way to get the last value?
#get first and last price in the series
value_count = 0
for item in data.price.values:
value_count = value_count + 1
begin_price = data.price.values[0]
end_price = data.price.values[value_count - 2]
- How do I reverse sort? I'm grabbing the last five instead of the first five because I couldn't figure that part out.
price_change_matrix_sorted = sorted(price_change_matrix,key=lambda x: x[1]) purchase_list = price_change_matrix_sorted[-5:]
Thanks for any guidance and suggestions!
Brian