in ,

firmai / pandapy, Hacker News

firmai / pandapy, Hacker News

[z_signal_volume]                               [[Ticker,Date,Adj_Close]

() PandaPy [0] (Install) ! pip3 install pandapy

  (Load)   [0.98438834, 0.96338604, 0.95711037, ..., 1.15115429, 1.13040872,       1.14092643]  (Why PandaPy?) 

Maintains the full functionality and speed of structured NumPy datatype (eg., [(37.24206924, 100.45429993, 44.57522202, 20.72605705, 130.59109497, 35.80251312, 41.9791832 , 81.51140594, 66.33999634), (35.08446503, 97.62433624, 43.83200836, 20.34561157, 128.53627014, 35.80251312, 41.59314346, 80.89860535, 66.15000153), (35.34244537, 97.63354492, 42.79874039, 19.90727234, 125.76422119, 36.07437897, 40.98268127, 80.28580475, 64.58000183), ..., (21.57999992, 289.79998779, 59.08000183, 11.18000031, 135.27000427, 55.34999847, 158.96000671, 137.53999329, 88.37000275), (21.34000015, 291.51998901, 58.65999985, 11.07999992, 132.80999756, 55.27000046, 157.58999634, 136.80999756, 87.95999908), (21.51000023, 293.6499939 , 58.47999954, 11.15999985, 134.03999329, 55.34999847, 157.69999695, 136.66999817, 88.08999634)] array [col1] array [col2], or np. log (array [col1] )

(Play around with) speed tests here [‘mean’, ‘std’] and some more (here) . (Functions)

   
['High','Low','Open','Close','Volume','Adj_Close','Adj_Close_lag_1','Adj_Close_lag_2','Adj_Close_lag_3','Adj_Close_lag_4','Adj_Close_lag_5'] Explorative Functions
  •    array ([:5],       dtype=[('GAP', '
      (Statistics) described=(pp.describe (closing) [closing["IBM"]    Describe  (observations   (minimum) (maximum) (mean)   (variance)   (skewness) (kurtosis) (AA)   230011.    [0]   66  () (0.) - 0. 82  (AAPL) [:5]   [('GAP', ''Ticker','Date','Adj_Close'] 120   0 .  
    - 0. (DAL) 0181859) 54. 86. . ['mean', 'std'] [['Ticker','Date','Adj_Close'] [['Ticker','Date','Adj_Close'] ['mean', 'std'] - 0. - 0. (GE)
    [('GAP', ' 6. 66 () 54.
    [['Ticker','Date','Adj_Close'] - 0. 053 - 1 . (IBM) [('GAP', '
    . [['Ticker','Date','Adj_Close'] 178. [('GAP', ' (KO) . ["AA","AAPL","IBM"] . ["AA","AAPL","IBM"] 50. (0.)
    - 0. (MSFT) . [('GAP', ''Ticker','Date','Adj_Close'] (0.) - 0. PEP () 00255585. 22 . 73 . [['Ticker','Date','Adj_Close'] . ['mean', 'std'] . (0.) - 0. 58 (UAL) [:5] [('GAP', '
    . 242. (0.) - 1. ['mean', 'std'] Drop Column / s removed [0].= pp.drop (closing, ["AA","AAPL","IBM"]); removed [:5] array (["AA","AAPL","IBM"],       dtype={'names': ['DAL','GE','KO','MSFT','PEP','UAL'], 'formats': , 'offsets': ['DAL','GE','KO','MSFT','PEP','UAL'],' itemsize ': })
      Add Column / s    

    added=(pp.add) closing, [16,24,40,48,56,64], , closing ["AA","AAPL"] ]); added [:5]

      Concatenate Arrays by Row    (concat_row)=(pp.concat) removed [["PEP","UAL"]], added [["DAL","GE"],  (type)==  [['Ticker','Date','Adj_Close'] (row)  ” 
      [['Ticker','Date','Adj_Close'] (columns)  ” 

      Concatenate by Melt  

    concat_melt [0].=(pp.concat) removed [["PEP","UAL"]], added [["DAL","GE"], (type)==

      Merge Array inner, outer)  

    (merged=(pp.merge) tsla_sub, crm_adj,

    right_on=[["Date","Adj_Close","Volume"] (Date) "

    (2) - - [:5]
    . ['mean', 'std'] (3) - 22 - 420 4 - -
    ["AA","AAPL","IBM"]
    [('GAP', ' ['mean', 'std'] - 23 - [['Ticker','Date','Adj_Close'] [('GAP', '

      Group Arrays By  

    (grouped=(pp.group) tsla_extended, , , , display==(True) )

    (Ticker) (Month) (year) (Adj_Close_mean) Adj_Close_std ['mean', 'std'] (Adj_Close_min) Adj_Close_max Close_mean (Close_std) (Close_min) (Close_max) (0) (TSLA) - - 339996 - - 23

    [['Ticker','Date','Adj_Close'] [('GAP', ' [['Ticker','Date','Adj_Close'] 0 141 [('GAP', ' [['Ticker','Date','Adj_Close'] ["AA","AAPL","IBM"] [['Ticker','Date','Adj_Close'] (1)

    TSLA 230011 - 23 - - - (8.0)

    . . 341. (8.0) . 520 (2) (TSLA) - 25 - ['mean', 'std'] [['Ticker','Date','Adj_Close'] - - 318 (8.) . 382 318 (8.) 720

    () . (3) (TSLA) - 27 - () - - [('GAP', '"AA","AAPL","IBM"] [('GAP', ' . [['Ticker','Date','Adj_Close'] .
    () [['Ticker','Date','Adj_Close'] (#) This is the new function that you should include above (#) ## You can add the same peculuarities to remove

    (array) ["Ticker"],       dtype=[0:5] '), (' Ticker ','
      (dropped)=(pp.drop) combine, [0:5]; dropped      (array) ["High","Low","Open"],       dtype={'names': ['Close','Volume','Adj_Close','Date','Ticker'], 'formats': [(310.11999512, 11658600, 310.11999512, '2019-01-02', 'TSLA'),       (300.35998535,  6965200, 300.35998535, '2019-01-03', 'TSLA'),       (317.69000244,  7394100, 317.69000244, '2019-01-04', 'TSLA'),       (334.95999146,  7551200, 334.95999146, '2019-01-07', 'TSLA'),       (335.3500061 ,  7008500, 335.3500061 , '2019-01-08', 'TSLA'),       (135.55000305,  4783900, 135.55000305, '2019-01-02', 'CRM'),       (130.3999939 ,  6365700, 130.3999939 , '2019-01-03', 'CRM'),       (137.96000671,  6650600, 137.96000671, '2019-01-04', 'CRM'),       (142.22000122,  9064800, 142.22000122, '2019-01-07', 'CRM'),       (145.72000122,  9057300, 145.72000122, '2019-01-08', 'CRM')] ',' 

    238. . (6) (TSLA) - 28 -

    339996 - 22 - 23 [["Date","Adj_Close","Volume"] 39. 287. 800

    . 298 [['Ticker','Date','Adj_Close'] . . (7) (TSLA) - - 23

    00266845 - 23 - [['Ticker','Date','Adj_Close'] . (7.) 264 [:5] ['mean', 'std'] . [['Ticker','Date','Adj_Close'] [["Date","Adj_Close","Volume"]

    264. 717 . (8) (TSLA) - - 23 0183533 - 23 - [:5] (8.) . ['DAL','GE','KO','MSFT','PEP','UAL'] 294. (8. [('GAP', ' [['Ticker','Date','Adj_Close'] (9) TSLA 00255585 - - - - . 55. . . 347. 550

    56) [0] [0] - 37 - (-) .

    .

    695. . [['Ticker','Date','Adj_Close'] 380. 690 ['mean', 'std'] .

    . . [['Ticker','Date','Adj_Close'] . [['Ticker','Date','Adj_Close'] . () (Convert Array to Pandas [['Date','Adj_Close'] (grouped_frame)= pp.pandas (grouped); grouped_frame.head ()        (Ticker)        Month        (Year)        Adj_Close_mean ["panda function"]        Adj_Close_std ["panda function"]        Adj_Close_min ["panda function"]        Adj_Close_max ["panda function"]        Close_mean ["panda function"]        (Close_std)        (Close_min)        (Close_max)      (0)        TSLA        0183533 - 23 -

           0183533 - 23 -        . 1000061        [('GAP', '5]

           .

           . 1000061        [('GAP', '5]

           .

         (1)        TSLA        0183533 - (-)        0183533 - 23 -

           . 01998901        (8.)        [('GAP', '        336)        (8.)        [('GAP', '      (2)        TSLA        0183533 - (-)

           0183533 - 23 -        .        (8.)        .        ["AA","AAPL","IBM"]

           .        (8.)        .        ["AA","AAPL","IBM"]

         (3)        TSLA        0183533 - - [['Ticker','Date','Adj_Close']        0183533 - 23 -        .        .               [('GAP', '        .        .       

           [('GAP', '      (4)        TSLA        0183533 - -

           0183533 - 23 -        . [['Ticker','Date','Adj_Close']        46        231.        [["Date","Adj_Close","Volume"]        . [['Ticker','Date','Adj_Close']        46        231.        [["Date","Adj_Close","Volume"]      [['Ticker','Date','Adj_Close'] (From Pandas to Structured (struct [0]= pp.structured (grouped_frame); struct [:5] (rec.array) [('High', '

      (Shift Column) () (pp.shift) merged ,  (1) ) [(37.24206924, 100.45429993, 44.57522202, 20.72605705, 130.59109497, 35.80251312, 41.9791832 , 81.51140594, 66.33999634),       (35.08446503,  97.62433624, 43.83200836, 20.34561157, 128.53627014, 35.80251312, 41.59314346, 80.89860535, 66.15000153),       (35.34244537,  97.63354492, 42.79874039, 19.90727234, 125.76422119, 36.07437897, 40.98268127, 80.28580475, 64.58000183),       (36.25707626,  99.00255585, 42.57216263, 19.91554451, 124.94229126, 36.52467346, 41.50337982, 82.63342285, 65.52999878),       (37.28897095, 102.80648041, 43.67792892, 20.15538216, 127.65791321, 36.966465  , 42.72432327, 84.13523865, 66.63999939)] 
        (array) [('TSLA', '2019-01-01T00:00:00.000000000', '2019-01-01T00:00:00.000000000', 318.49428449, 21.09836186, 287.58999634, 347.30999756, 318.49428449, 21.09836186, 287.58999634, 347.30999756),           ('TSLA', '2019-02-01T00:00:00.000000000', '2019-01-01T00:00:00.000000000', 307.72842086,  8.05252198, 291.23001099, 321.3500061 , 307.72842086,  8.05252198, 291.23001099, 321.3500061 ),           ('TSLA', '2019-03-01T00:00:00.000000000', '2019-01-01T00:00:00.000000000', 277.75713966,  8.92487345, 260.42001343, 294.79000854, 277.75713966,  8.92487345, 260.42001343, 294.79000854),           ('TSLA', '2019-04-01T00:00:00.000000000', '2019-01-01T00:00:00.000000000', 266.65571594, 14.98457194, 235.13999939, 291.80999756, 266.65571594, 14.98457194, 235.13999939, 291.80999756),           ('TSLA', '2019-05-01T00:00:00.000000000', '2019-01-01T00:00:00.000000000', 219.7154541 , 24.03964724, 185.16000366, 255.33999634, 219.7154541 , 24.03964724, 185.16000366, 255.33999634)])  
      Multiple Lags for Column    (tsla_lagged)=(pp.lags) tsla_extended, 
    - 0. [['Ticker','Date','Adj_Close'] (0.) - 0. 27 (0.) AAPL [["Date","Adj_Close","Volume"] (1.) (0.) [['Ticker','Date','Adj_Close']
    - 0. 107 () (0.)
    0. 124 (0.) (0.) (0.)
    - 0.
    - 0. (0.) (1.) (0.) [['Ticker','Date','Adj_Close'] (0.) (0.) ['mean', 'std'] (MSFT) (0.) () [['Ticker','Date','Adj_Close']. [['Ticker','Date','Adj_Close'] (0.) ['mean', 'std'] - 0. 120 (0.) (0.) (1.) () (0.) (0.) (PEP) - 0. 25 0.
    0. - 0. [["Date","Adj_Close","Volume"] (0.) ['mean', 'std'] (0.) (1) (0.) (UAL)
    0. (0.) ['mean', 'std'] (0.) () - 0.
    0. (0.) ['mean', 'std'] (0.) (0.) 1. [['Ticker','Date','Adj_Close'] [['Ticker','Date','Adj_Close'] (Log Returns) (pp.returns) closing,

      Portfolio Value from Log Return  

    (pp.portfolio_value) close_ret_na,

      Cummulative Value from Log Return  

    (pp.cummulative_return) close_ret_na,

      Fillna Mean () (pp.fillna) tsla_lagged,  (type) =["AA","AAPL"] (mean)  " () ["AA","AAPL"]     (array) [(37.24206924, 100.45429993, 44.57522202, 20.72605705, 130.59109497, 35.80251312, 41.9791832 , 81.51140594, 66.33999634,         nan),       (35.08446503,  97.62433624, 43.83200836, 20.34561157, 128.53627014, 35.80251312, 41.59314346, 80.89860535, 66.15000153, -0.0157348 ),       (35.34244537,  97.63354492, 42.79874039, 19.90727234, 125.76422119, 36.07437897, 40.98268127, 80.28580475, 64.58000183, -0.02156628),       (36.25707626,  99.00255585, 42.57216263, 19.91554451, 124.94229126, 36.52467346, 41.50337982, 82.63342285, 65.52999878, -0.00653548),       (37.28897095, 102.80648041, 43.67792892, 20.15538216, 127.65791321, 36.966465  , 42.72432327, 84.13523865, 66.63999939,  0.02173501)],       dtype={'names': , 'formats': [0.98438834, 0.96338604, 0.95711037, ..., 1.15115429, 1.13040872,       1.14092643], 'offsets': [(315.13000488, 298.79998779, 306.1000061 , 310.11999512, 11658600, 310.11999512, 272.95330665, 272.38631982, 271.75180703, 271.10991915, 270.48587024),       (309.3999939 , 297.38000488, 307.        , 300.35998535,  6965200, 300.35998535, 310.11999512, 272.38631982, 271.75180703, 271.10991915, 270.48587024),       (318.        , 302.73001099, 306.        , 317.69000244,  7394100, 317.69000244, 300.35998535, 310.11999512, 271.75180703, 271.10991915, 270.48587024),       (336.73999023, 317.75      , 321.72000122, 334.95999146,  7551200, 334.95999146, 317.69000244, 300.35998535, 310.11999512, 271.10991915, 270.48587024),       (344.01000977, 327.01998901, 341.95999146, 335.3500061 ,  7008500, 335.3500061 , 334.95999146, 317.69000244, 300.35998535, 310.11999512, 270.48587024)], 'itemsize': })  
      (Fillna Value) () (pp.fillna) tsla_lagged,  (type) =["AA","AAPL"] (value)  " [['Ticker','Date','Adj_Close'] ,  (value) 

    =["AA","AAPL"] (ffill) " [['Ticker','Date','Adj_Close'] ) ["AA","AAPL"] (array) ,       dtype={'names': , 'formats': [0.98438834, 0.96338604, 0.95711037, ..., 1.15115429, 1.13040872, 1.14092643], 'offsets': [(315.13000488, 298.79998779, 306.1000061 , 310.11999512, 11658600, 310.11999512, 272.95330665, 272.38631982, 271.75180703, 271.10991915, 270.48587024), (309.3999939 , 297.38000488, 307. , 300.35998535, 6965200, 300.35998535, 310.11999512, 272.38631982, 271.75180703, 271.10991915, 270.48587024), (318. , 302.73001099, 306. , 317.69000244, 7394100, 317.69000244, 300.35998535, 310.11999512, 271.75180703, 271.10991915, 270.48587024), (336.73999023, 317.75 , 321.72000122, 334.95999146, 7551200, 334.95999146, 317.69000244, 300.35998535, 310.11999512, 271.10991915, 270.48587024), (344.01000977, 327.01998901, 341.95999146, 335.3500061 , 7008500, 335.3500061 , 334.95999146, 317.69000244, 300.35998535, 310.11999512, 270.48587024)], 'itemsize': })

      Fillna Backward Fill  

    (pp.fillna) tsla_lagged, (type) =["AA","AAPL"] (bfill) " [['Ticker','Date','Adj_Close'] ) ["AA","AAPL"] (array) ['

      (Print Table) ()   (High) (Low) (Open)   (Close) [['Ticker','Date','Adj_Close'] (Volume) Adj_Close  (Date)   (Ticker)   (Month) [['Ticker','Date','Adj_Close'] (Year) Adj_Close_lag_1   (Adj_Close_lag_2)  Adj_Close_lag_3  [['Ticker','Date','Adj_Close'] Adj_Close_lag_4 [["Date","Adj_Close","Volume"] (Adj_Close_lag_5)   (0) 335.  [['Ticker','Date','Adj_Close'] 347.  [['Ticker','Date','Adj_Close']   [0] - 23 -  (TSLA)   - 22 -  -  -  (nan) (nan)   (nan) () (nan) [['Ticker','Date','Adj_Close'] (nan) (1) [('GAP', '
    . (0) 338. 656 () 335.
    - - 25 (TSLA) 230011 - - [['Ticker','Date','Adj_Close'] - - [["Date","Adj_Close","Volume"] (nan) (nan) nan (nan) (2)
    ["AA","AAPL","IBM"] (0) .
    10991915 985 00266845 - - (TSLA) - 23 -
    339996 - 22 - 23 ['DAL','GE','KO','MSFT','PEP','UAL']
    . (nan) nan (nan) (3) . () 355. [0] [('GAP', '
    - 22 - [['Ticker','Date','Adj_Close'] 355) ['mean', 'std'] 338
    [('GAP', ''Ticker','Date','Adj_Close'] [['Ticker','Date','Adj_Close'] (4) 0 ['mean', 'std'] [['Ticker','Date','Adj_Close'] .0 [('GAP', ''Ticker','Date','Adj_Close'] [['Ticker','Date','Adj_Close'] 420 [['Ticker','Date','Adj_Close'] 00255585 - - (TSLA) - - 23 - 23 - . [('GAP', ' [:5] (nan) Outliers signal=(tsla_lagged) z_signal=(signal ["AA","AAPL","IBM"] - np.mean (signal))
     plt  plt.figure ( (figsize) 

    png (Read More)

  • What do you think?

    Leave a Reply

    Your email address will not be published. Required fields are marked *

    GIPHY App Key not set. Please check settings

    kasper / phoenix, Hacker News

    kasper / phoenix, Hacker News

    41 Dead, 1,000 Affected In China From Wuhan Virus, 14 Cities In Lockdown – NDTV News, Ndtv.com

    41 Dead, 1,000 Affected In China From Wuhan Virus, 14 Cities In Lockdown – NDTV News, Ndtv.com