Guest User

Untitled

a guest
Jan 22nd, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.39 KB | None | 0 0
  1. from astroplan import Observer
  2. from astropy import units as u
  3. from astropy.time import Time, TimeDelta
  4. from numpy import nan, where
  5. from pandas import read_csv
  6. from urllib.request import urlretrieve
  7. from zipfile import ZipFile
  8.  
  9. if __name__ == "__main__":
  10.     urlretrieve('http://bossa.pl/pub/futures/mstock/mstfut.zip', 'mstfut.zip')
  11.     with ZipFile('mstfut.zip', 'r') as fd:
  12.         fd.extract('FW20.mst', '.')
  13.     fw20 = read_csv('FW20.mst', parse_dates=['<DTYYYYMMDD>'])
  14.     fw20 = fw20.rename(columns={'<DTYYYYMMDD>': 'date', '<CLOSE>': 'close'})
  15.  
  16.     gpw = Observer(longitude=21.023616 * u.deg, latitude=52.230268 * u.deg,
  17.                    elevation=100 * u.m, name="gpw", timezone="Europe/Warsaw")
  18.  
  19.     fw20XXI = fw20[fw20.date.dt.year > 2000]
  20.     times = Time(fw20XXI.date, format='datetime64')
  21.     times_hour_ago = times - TimeDelta(3600, format='sec')
  22.     change = fw20XXI.close - fw20XXI.close.shift()
  23.     moon = gpw.moon_illumination(times)
  24.     waxing = gpw.moon_illumination(times_hour_ago) < gpw.moon_illumination(times)
  25.     flag = ((moon > 0.3) & waxing) | (moon > 0.95)
  26.     fw20XXI = fw20XXI.assign(lycan=where(flag, change, nan), vampire=where(flag, nan, change))
  27.     stats = fw20XXI[['vampire', 'lycan']].groupby(fw20XXI.date.dt.year).sum()
  28.     stats = stats.assign(vampire_win=stats.vampire > stats.lycan)
  29.     print(stats)
  30.     print(fw20XXI[['vampire', 'lycan']].sum())
Advertisement
Add Comment
Please, Sign In to add comment