In [119]:
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import math

from basic_artificial_market import ArtificialMarket

In [220]:
import numpy as np
import matplotlib.pyplot as plt
import math

class ArtificialMarket():
    def __init__(self, num_player=1000, ganma=1000, sigma=0.06, P_sigma=30):
        self.num_player = num_player
        self.random_state = np.random.RandomState()
        self.sigma = sigma
        self.P_sigma = P_sigma
    
    def weight(self, w_1_max=1, w_2_max=100, w_3_max=1):
        num_player = self.num_player
        weight_1 = np.zeros(num_player)
        weight_2 = np.zeros(num_player)
        weight_3 = np.zeros(num_player)
        random_state = self.random_state
        for i in range(num_player):
            weight_1[i] = random_state.uniform()*w_1_max
            weight_2[i] = random_state.uniform()*w_2_max
            weight_3[i] = random_state.uniform()*w_3_max
        weight = [weight_1, weight_2, weight_3]
        return weight
    
    def ganma(self, ganma_max=10, num_player=None):
        random_state = self.random_state
        if num_player is None:
            num_player = self.num_player
        ganma = np.array([])
        for i in range(num_player):
            ganma = np.append(ganma, int(random_state.uniform(ganma_max)))
        return ganma
    
    def P_t(self, past_data, delta_l, delta_t):
        if np.sum(delta_t) <= delta_l:
            P_t = past_data[-1]
        else: 
            d = 0
            j = 0
            while d <= delta_l:
                d += delta_t[-j]
                j += 1
            P_t = past_data[-j]
        return P_t
    
    def r_t_h(self, past_data, P_t, ganma):
        if len(past_data) < ganma:
            r_t_h = np.log10(P_t/past_data[0])
        else:
            past_data_ganma = past_data[-ganma]
            r_t_h = np.log10(P_t/past_data_ganma)
        return r_t_h
        
    def one_market_model(self, delta_l, w, ganma, fdmtl=10000.0, b_limit=None, s_limit=None, t=0, delta_t=None, past_data=None, market_order=0, delta=1):
        num_player = self.num_player
        sigma = self.sigma
        P_sigma = self.P_sigma
        P_f = fdmtl
        
        if past_data is None:
            past_data = np.array([P_f])
        if b_limit is None:
            b_limit = np.array([])
        if s_limit is None:
            s_limit = np.array([])
        
        if delta_t is None:
            delta_t = np.array([])
            
        w_1 = w[0]
        w_2 = w[1]
        w_3 = w[2]
        r_t_e = np.zeros(num_player)
                
        for i in range(num_player):
            P_t_1 = past_data[-1]
            #P_t_1 = self.P_t(past_data, delta_l, delta_t)
            
            r_t_h = self.r_t_h(past_data, P_t_1, ganma[i])
            
            e_t = np.random.normal(0, sigma)
            
            r_t_e[i] = (w_1[i]*np.log10(P_f/P_t_1) + w_2[i]*r_t_h + w_3[i]*e_t)/(w_1[i] + w_2[i] + w_3[i])
            P_e = P_t_1*math.exp(r_t_e[i])
            
            P_o = np.random.normal(P_e, P_sigma)
            
            #print w_1[i]*np.log10(P_f/P_t_1), w_2[i]*r_t_h, r_t_e[i]
            
            if P_e > P_o:
                P_o = round(P_o, 1)
                if len(s_limit) > 10 and np.min(s_limit) < P_o:
                    market_order += 1
                    P_t = np.min(s_limit)
                    s_limit = np.delete(s_limit, np.argmin(s_limit))
                else:
                    b_limit = np.append(b_limit, P_o)
                    P_t = P_t_1
            else:
                P_o = round(P_o, 1)+0.1
                if len(b_limit) > 10 and np.max(b_limit) > P_o:
                    market_order += 1
                    P_t = np.max(b_limit)
                    b_limit = np.delete(b_limit, np.argmax(b_limit))
                else:
                    s_limit = np.append(s_limit, P_o)
                    P_t = P_t_1
            past_data = np.append(past_data, P_t)
            delta_t = np.append(delta_t, np.random.exponential(delta))
            t += delta_t[-1]
        return t, delta_t, past_data, b_limit, s_limit, market_order
        
    def one_market_simulation(self, delta_l, o_max=10000, fdmtl=10000):
        o = 0
        w = self.weight()
        ganma = self.ganma()
        t, delta_t, past_data, b_limit, s_limit, market_order = self.one_market_model(delta_l, w, ganma, fdmtl)
        while o < o_max:
            t, delta_t, past_data, b_limit, s_limit, market_order = self.one_market_model(delta_l, w, ganma, fdmtl, b_limit, s_limit, t, delta_t, past_data, market_order)
            o += 1
        return past_data, t, market_order
    
    def rad(self, past_data, fdmtl=10000.0):
        p = 0
        for i in range(len(past_data)):
            p += math.fabs(float(past_data[i]) - fdmtl)/fdmtl
        m = 1.0/float(len(past_data))*p
        return m
    
    def agreed_rate(self, past_data, market_order):
        print market_order
        agreed_rate = float(market_order)/float(len(past_data))
        return agreed_rate

In [232]:
AM = ArtificialMarket()
k, t, market_order= AM.one_market_simulation(0, 10)
plt.plot(k)
AM.rad(k)


Out[232]:
0.0002801908917371384

In [233]:
AM.agreed_rate(k, market_order)


938
Out[233]:
0.0852649759112808

In [205]:
k[-100:]


Out[205]:
array([ 10007.5,  10007.5,  10007.5,  10007.5,  10007.5,  10007.5,
        10007.5,  10007.6,  10007.7,  10007.7,  10007.7,  10007.7,
        10007.7,  10007.7,  10007.7,  10002.6,  10002.6,  10002.6,
         9986.1,   9981.8,   9980.4,   9980.4,   9980.4,   9980.4,
         9980.4,   9980.4,   9980.4,   9980.4,   9980.4,   9980.4,
         9980.4,   9980.4,   9980.4,   9980.4,   9979.7,   9979.7,
         9979.7,   9979.7,   9979.7,   9975.3,   9975.3,   9975.3,
         9974.8,   9974.8,   9974.8,   9974.8,   9973.5,   9973.5,
         9973.5,   9973.5,   9973.5,   9973.5,   9973.1,   9973.1,
         9973.1,   9973.1,   9973.1,   9973.1,   9972.8,   9972.8,
         9972.8,   9972.8,   9979.8,   9979.8,   9979.8,   9979.9,
         9994. ,   9994. ,   9974.3,   9974.3,   9972.3,   9972.3,
         9972.3,   9972.3,   9972.3,   9971.2,   9971.2,   9971.2,
         9971.2,   9971.2,   9971.2,   9977.9,   9977.9,   9977.9,
         9977.9,   9977.9,   9984.8,   9984.8,   9984.8,   9976. ,
         9997.4,   9997.4,   9997.4,   9998.3,   9998.3,   9999.1,
         9999.1,   9999.1,   9999.1,   9999.1])

In [13]:
AM = ArtificialMarket()
k, t= AM.one_market_simulation(10, 5)
plt.plot(k)
round(AM.rad(k), 8)


[  9929.35884192   9930.87953013   9967.12446328   9958.50311947
   9925.02591151   9955.25973876   9859.97561989   9971.19247792
   9856.5748648    9858.38623857   9941.9959441    9974.64065106
   9603.87685759   9949.45632776   9896.90878477   9964.57888453
   9966.04145634   9939.35075343   9908.33779868   9976.16167657
   9972.93139725   9954.47319069   9894.62786427   9960.53041333
   9889.4690011    9919.28027802   9935.59200216   9869.60099255
   9657.66030342   9927.3485805    9853.68020584   9846.62891555
   9887.3573327    9965.88684522   9966.81439917   9658.22717816
   9871.69394511   9930.86480946   9928.35718587   9943.23048688
   9923.43449502   9955.82887509   9945.29654282   9964.43560748
   9951.19380712   9693.02595979   9972.58159332   9930.87578044
   9905.57629714   9908.87077576   9978.15078842   9909.77742927
   9829.78426505   9944.98572956   9970.78828919   9966.62252228
   9941.94758644   9970.68702484   9919.91224116   9718.96209267
   9938.80507757   9843.1329228    9960.84019172   9906.48800055
   9950.95653991   9919.36784717   9955.20957863   9952.40512602
   9986.91939004   9976.05212827   9981.00880113   9824.43114928
   9582.41757006   9905.88009664   9941.29205988   9976.18409409
   9778.2966716    9845.69443278   9975.60189624   9987.65615436
   9985.48146168   9969.27868664   9978.97516467   9739.54927791
   9982.4614391    9795.61551019   9946.19805912   9913.85267894
   9951.40180647   9838.76898894   9935.74599971   9976.86012856
   9985.04773097   9973.33452925   9738.71783161   9979.50716274
   9976.44265836   9980.07140326   9966.00830092   9987.20890174
   9977.0057526    9908.57533259   9978.77582312   9924.69449956
   9975.90959619   9977.43122296   9977.68293938   9882.51390673
   9938.5310512    9928.66476894   9964.76142598   9972.20252891
   9943.59538447   9931.87197688   9989.30812734   9944.83959404
   9988.37552984   9967.95582205   9937.7831487    9981.5111055
   9812.98741225   9976.19147529   9948.75754591   9972.04603138
   9977.22690726   9930.73370858   9787.80788285   9970.23247536
   9908.88468184   9956.25172803   9955.46521807   9932.95736775
   9891.1950322    9970.48733957   9979.98385086   9856.79712652
   9535.21675749   9780.92693907   9988.97744467   9885.72523698
   9955.74896008   9959.44231789   9953.93233504   9978.22488139
   9990.34098562   9994.08877069   9939.32307483   9991.53020326
   9997.44176818   9985.71544203   9965.58313735   9998.84350919
   9942.2005091    9970.39047758   9938.21429523   9968.20093975
   9967.33239548   9966.01369584   9910.0903825   10004.22761795
   9842.80742945   9968.81201931   9811.10410577   9995.79035212
   9878.23180151   9992.78507178   9992.13872094   9981.34623464
   9870.69698459   9949.64711984   9932.61143509   9971.90829786
  10002.7970224    9945.03938121   9932.2945462    9976.71769035
  10004.81045945   9895.35043906   9985.50881013  10001.50628383
  10001.3876241    9970.3638932    9987.61761436   9996.97061236
   9952.98955595   9987.96943396   9899.2155643    9962.67758334
   9991.58157642   9902.74002159   9995.07259556   9935.1717883
   9988.32586099   9853.32027199   9843.27946172   9862.46132539
   9987.33623937  10006.22687558   9987.88409566   9985.90763325
   9934.47636863   9831.79629762   9952.41643106   9980.2946645
   9920.61770509   9975.42843479  10002.76452719   9961.77639306
   9957.82257159   9949.25665777  10001.78279458   9921.84934637
   9965.2029312    9881.70784134   9921.38318591   9994.84803368
   9987.51569627   9956.67615121   9960.27685541  10002.22351252
   9902.04928216   9944.96606164  10004.01212155  10003.7060191
   9960.75310126   9967.74909945   9996.97329117   9994.66756365
  10002.17229372   9935.97861186   9493.86687644   9986.87594501
   9349.90476354   9919.33153355   9977.45293199   9975.50047155
   9960.97897157  10002.79409613   9990.66046254   9983.37924413
   9951.1161818    9957.52657441   9950.68613638   9926.25566529
   9977.41175788   9922.8294214   10001.32201625   9838.49083245
   9998.58244292   9987.25496031   9988.52067855   9983.37536254
   9990.06710809   9936.64194275   9952.3702263    9936.80512778
   9946.22032294   9948.88249596  10001.329788     9974.21459933
  10003.04817239   9981.30495479   9963.11217892   9961.57629319
   9991.23864759   9932.97383246   9624.80920976   9963.70482671
   9980.13465742   9999.09549099   9992.71969252   9854.87737824
  10005.11843906   9887.44372414   9977.93372704  10003.36248409
   9804.8161207    9985.22026011   9923.50961307   9962.04698531
   9883.95153908   9999.5430952    9761.26001459  10000.06217223
   9970.07683444   9835.39524146   9956.65284192   9920.43407794
   9979.54031627   9991.58961759   9948.92286566   9990.90481875
   9977.71361642  10004.01299308   9740.17982621   9793.59378596
   9748.91492005   9831.6682247    9890.27125918   9982.20081196
   9994.03225575   9935.17192554   9982.57534251  10000.04952318
   9959.22834814   9989.18377439   9982.66957153   9910.25700598
   9937.14579423   9868.98917903   9954.17905691  10005.40045714
   9998.72112321   9773.47243211  10000.01433281   9944.82955728
   9992.42754852   9975.59173342   9958.05252202   9980.27807183
   9916.81771931   9913.49406417   9944.50139477   9848.38343408
   9996.12154416   9938.95346439   9965.19143073   9895.04080034
   9939.55149185   9929.78832339   9960.46902854   9985.27325278
   9915.67155379   9892.58698954   9931.8588127    9986.60722698
   9747.79254443   9955.76477926  10003.61503049   9985.49693985
   9939.46125681  10002.9394607    9999.6204625    9930.96533929
   9990.60160379   9730.64562562   9998.29782501   9962.68286563
   9998.06128126   9767.72715542   9846.95687003   9986.0381435
   9932.7978683   10004.02135757   9944.26621792   9968.01328299
   9947.93801641   9917.64122503   9995.40604985   9914.4706049
   9957.95995446  10004.76752969   9965.71807954   9989.8458797
   9896.38876335   9439.47053709   9982.10056575  10002.98276116
   9835.38975334   9911.57644618  10005.09817533   9956.51624833
   9740.04869867   9990.57970743   9971.09977174   9854.01517466
   9942.32524601   9969.41938894   9998.08724184   9876.72643412
   9971.31964207   9928.92139399   9852.42634523   9949.87662555
  10021.35312995  10038.73893074  10041.49871365  10042.56325291
  10010.94588884   9980.26322916  10013.76805979   9978.24766554
  10014.3860709    9856.75022021  10007.75522939  10015.54669538
   9818.57847451   9979.4418075    9938.65785236   9931.83497117
   9958.88599977   9817.82430837   9999.3415174    9984.56824869
  10034.95939065  10037.19673621   9956.26428853  10005.01747254
  10026.94481656  10000.60900153   9821.04957488   9994.66391739
  10045.12484488   9792.59444826  10020.5847365   10028.46282495
  10034.76129645  10023.46354235  10028.32486608  10036.2572771
  10016.45239009  10010.00328977  10025.98546965  10019.50830999
  10044.23361778  10018.50014908  10022.07454605  10047.68567088
  10035.44538897  10049.88135141  10041.23988909  10050.35154217
   9994.61113764  10031.00944992  10017.33026455] [ 10155.57019688  10096.26369191  10090.48854606  10305.85577591
  10092.36103054  10190.64360488  10078.61772866  10296.60677451
  10116.52546515  10286.19671172  10144.0538066   10075.20898711
  10080.67782603  10117.08834157  10086.38917675  10170.59733375
  10224.72636481  10213.44131035  10108.90150409  10108.02656841
  10089.99283012  10070.65482755  10068.48798322  10161.71994247
  10084.17059546  10076.84292398  10154.3897165   10292.57281788
  10078.85794884  10071.73713013  10090.52230792  10095.57199626
  10354.32990557  10126.2500781   10940.13375151  10074.11554704
  10080.87028756  10124.33606204  10114.65723693  10076.10530544
  10075.11146402  10085.85748916  10095.42669157  10069.70430541
  10115.63118449  10202.88130835  10070.78770114  10115.68539858
  10075.52734609  10110.72997912  10080.516798    10097.97862991
  10114.75493198  10082.08217685  10072.05417161  10083.91724329
  10089.5161144   10091.23898258  10243.79386697  10146.95369563
  10071.97341919  10130.93059228  10100.98459221  10217.32276159
  10100.76385987  10113.16832624  10073.59808541  10092.78388413
  10077.80135737  10301.04477055  10075.08487525  10080.864564
  10191.00943433  10200.68760204  10075.90802733  10099.58801646
  10238.3408202   10149.86249702  10521.01466036  10068.35313515
  10075.55994738  10087.42239428  10109.54656601  10677.26918713
  10098.62867981  10071.87919988  10101.41609082  10148.27043981
  10078.21624543  10209.9792732   10282.62668885  10081.76487015
  10146.67525834  10070.58689925  10127.62856275  10069.18887105
  10197.27770359  10340.7080662   10092.78554518  10203.64929828
  10076.81865515  10068.47276188  10179.1141298   10093.01618536
  10108.40688597  10119.32742408  10124.60639239  10115.32321877
  10143.41182115  10097.91547825  10150.78349904  10152.52897462
  10165.94012204  10109.06944707  10083.32146126  10070.25451267
  10107.18800449  10186.95405441  10087.84180131  10288.34425913
  10071.85290466  10089.4679633   10119.57040542  10104.37174545
  10077.19083497  10081.45702505  10181.34730784  10099.2809643
  10104.30301939  10090.73129601  10140.02363558  10171.12414927
  10079.65371195  10112.70736011  10080.27073044  10171.06220176
  10123.49830639  10141.05834067  10111.21782824  10116.83230871
  10307.25180392  10116.13627384  10102.5636721   10096.88604125
  10082.08774366  10074.87733323  10128.32413627  10124.50476672
  10145.57794989  10086.42042175  10176.06627841  10146.17946076
  10114.76412161  10082.00409551  10166.37061041  10128.07898349
  10363.04519844  10084.60869167  10094.10458996  10074.24513728
  10078.56766291  10153.18392221  10096.91784959  10131.37287792
  10119.69141705  10099.06095607  10116.70661014  10307.90533427
  10100.40970718  10253.22403851  10108.99824478  10075.21524546
  10090.09930864  10090.3307939   10129.75520881  10132.72512891
  10206.26438518  10104.26059858  10084.22034983  10144.4438522
  10083.48766446  10070.43582943  10123.76355031  10069.40486265
  10214.9434499   10076.04074018  10112.00971287  10222.04108732
  10187.58269111  10151.26516305  10083.10302879  10190.46126366
  10104.39757918  10284.05971587  10089.3136433   10077.26888822
  10154.59971754  10104.35768966  10095.62876862  10069.23645187
  10115.26172976  10072.57920472  10073.69584627  10089.39007253
  10075.37601583  10542.57364032  10117.55395894  10287.32018717
  10165.67789182  10107.29414093  10086.71086238  10130.67024907
  10082.46423326  10114.42884818  10095.79116825  10093.64875882
  10106.10102152  10283.48274064  10195.40989459  10071.67695001
  10163.1310184   10116.35293379  10149.50528255  10080.26877578
  10110.05929166  10243.81577964  10075.12746669  10094.6881163
  10133.25764082  10112.16629051  10135.37688357  10122.53540552
  10082.09359534  10105.78871944  10122.31881751  10163.04261311
  10132.21547449  10537.69183677  10697.79997085  10084.25493318
  10097.88679216  10116.05462438  10088.60998028  10217.1699097
  10082.52652817  10098.30108231  10126.75773589  10148.84212863
  10145.60701942  10167.9031936   10131.59754271  10156.8931578
  10071.87951023  10074.79481279  10117.95217245  10098.1490943
  10105.60624984  10083.22513376  10071.75590674  10194.67687362
  10084.1421289   10122.33724066  10078.33817647  10146.0526749
  10185.67177635  10073.82026131  10071.05744643  10078.06341035
  10089.87695106  10134.7600539   10077.44398456  10393.73626054
  10110.15782706  10152.81302001  10579.42507546  10126.62241044
  10069.08158349  10116.28894731  10100.78365921  10202.39058876
  10122.71656335  10069.63685396  10109.29842414  10193.59607875
  10178.09731401  10152.48312843  10151.10722399  10095.8490561
  10097.53995937  10092.63679107  10082.89177878  10068.25781305
  10280.62967416  10140.52597463  10077.99057823  10191.17709306
  10074.69269636  10222.94748317  10070.84768042  10107.29694687
  10133.05662957  10199.08943679  10226.54529346  10118.33459984
  10096.52361687  10102.8317718   10084.95290407  10094.93585802
  10209.79768928  10166.7158932   10116.97186701  10138.98190793
  10072.75433028  10383.84504036  10080.95058808  10099.39923384
  10073.21853428  10210.0422834   10085.263908    10082.8231695
  10115.49279828  10097.17587203  10137.39841372  10114.64789899
  10106.05460313  10104.59480232  10224.01130845  10145.7391727
  10180.7099505   10169.65790052  10124.18171037  10118.92645109
  10131.87168333  10069.94280391  10165.04877895  10123.12536089
  10097.81234465  10082.29246303  10089.03230412  10137.37757287
  10093.66453661  10091.93797674  10071.44202853  10319.91787188
  10141.69640242  10299.48323242  10087.25614396  10132.12087956
  10093.00077509  10158.50722283  10142.76084706  10134.90849303
  10110.37541561  10070.94505973  10082.27677637  10072.21120064
  10147.27076463  10597.08680689  10081.96033732  10095.81051462
  10172.51873597  10143.71392948  10098.86487668  10115.37448263
  10086.25559906  10073.29568209  10106.01454322  10079.45287466
  10107.71102751  10088.11421064  10139.83640903  10183.28912463
  10128.22926874  10085.47197274  10088.65942104  10120.95215782
  10085.40794782  10102.91503482  10187.33316134  10069.62941489
  10095.79942115  10092.65174013  10124.35624145  10142.4248802
  10134.61177723  10148.38455673  10127.85538751  10069.77844963
  10270.92416758  10128.68131285  10079.2105003   10137.00923422
  10109.69945673  10081.44823278  10142.90365616  10116.10434301
  10551.59082112  10077.24608473  10082.17506502  10166.97096497
  10074.84028114  10089.74438759  10262.50889426  10085.46073281
  10089.91520791  10103.83630699  10210.04634808  10122.01795918
  10155.95891228  10070.2782494   10098.347941    10077.44185439
  10437.93627897  10100.21477078  10195.88968333  10086.2343723
  10071.12453405  10138.1940813   10099.06590591  10079.18696447
  10235.39611516  10080.70447596  10111.12206639  10104.46884776
  10105.29100555  10105.26841963  10167.87599268  10084.00578294
  10111.84030439  10094.17982354  10123.63376633  10170.35621984
  10111.98198884  10073.24905329  10091.05018389  10110.43530654
  10085.56621202  10082.47270592  10097.70478038  10159.38414504
  10094.27190563  10085.34964053  10145.20657581  10099.95399207
  10113.8454903   10146.99201333  10140.09858806  10100.54811817
  10071.03357623  10139.28678529  10077.81831997  10228.15166119
  10412.41761399  10120.33417991  10087.60901401  10111.35114859
  10274.75230435  10157.07495163  10134.26679344  10075.83152408
  10084.81630936  10101.19277339  10110.05059278  10116.725808
  10123.39265558  10115.41877001  10110.3272729   10083.03495322
  10151.61613878  10137.77484631  10143.69953725  10224.41014816
  10076.66309358  10128.03040402  10095.68393362  10106.03093116
  10152.41961601  10166.73207396  10105.20195115  10073.30928825
  10269.49791903  10132.45515917  10093.59024978  10071.66937387
  10145.78146559  10122.96985265  10108.71210106  10136.28835969
  10125.16860279  10156.89323768  10122.01351092  10077.51482331
  10138.2885587   10095.47115159  10150.72102771  10139.88518082
  10072.97897504  10080.7072722   10077.65806547]
Out[13]:
0.00775557

In [218]:
j = np.where(k == min(k))
j


Out[218]:
(array([14, 15, 16, 17, 18, 19, 20]),)

In [221]:
k[20:1000]


Out[221]:
array([ 9833.27207567,  9845.8749886 ,  9845.8749886 ,  9845.8749886 ,
        9845.8749886 ,  9845.8749886 ,  9845.8749886 ,  9845.8749886 ,
        9845.8749886 ,  9845.8749886 ,  9845.8749886 ,  9853.41285104,
        9853.41285104,  9853.41285104,  9867.44270662,  9853.41285104,
        9867.44270662,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9867.44270662,  9867.44270662,
        9867.44270662,  9867.44270662,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9867.44270662,  9867.44270662,
        9867.44270662,  9867.44270662,  9867.44270662,  9867.44270662,
        9867.44270662,  9867.44270662,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9855.91445161,
        9855.91445161,  9855.91445161,  9855.91445161,  9855.91445161,
        9853.41285104,  9855.91445161,  9855.91445161,  9855.91445161,
        9853.41285104,  9855.91445161,  9855.91445161,  9855.91445161,
        9855.91445161,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9855.91445161,  9855.91445161,  9855.91445161,
        9855.91445161,  9853.41285104,  9855.91445161,  9855.91445161,
        9855.91445161,  9855.91445161,  9855.91445161,  9855.91445161,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9855.91445161,  9855.91445161,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.99780079,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.99780079,  9853.41285104,
        9853.99780079,  9853.99780079,  9853.41285104,  9853.99780079,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.99780079,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.41285104,  9853.41285104,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.41285104,  9853.41285104,  9853.41285104,  9853.41285104,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.99780079,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.99780079,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.71659773,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.99780079,  9853.99780079,  9853.99780079,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.99780079,
        9853.99780079,  9853.99780079,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.73760995,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.73760995,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.73760995,
        9853.73760995,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.73760995,  9853.73760995,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.73760995,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.73760995,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.73760995,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.71659773,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.73760995,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.73760995,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.73760995,  9853.73760995,  9853.73760995,
        9853.73760995,  9853.73760995,  9853.73760995,  9853.71659773,
        9853.73760995,  9853.73760995,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.73760995,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773,
        9853.71659773,  9853.71659773,  9853.71659773,  9853.71659773])

In [311]:
for i in range:
    np.random.exponential(1)


Out[311]:
1.4960887944860213

In [464]:
k = [1, 3, 4, 5, 1, 5]
k = np.delete(k, np.max(k))
k


Out[464]:
array([1, 3, 4, 5, 1])

In [ ]:
if past_data[-1] > past_data[-2] + 100:
                print past_data[-1], past_data[-2], i, P_t_1, P_e, P_o, r_t_e[i], math.exp(r_t_e[i])
            elif past_data[-1] < past_data[-2] - 100:
                print past_data[-1], past_data[-2], i, P_t_1, P_e, P_o, r_t_e[i], math.exp(r_t_e[i]

In [24]:
random_state = np.random.RandomState()
random_state.uniform()


Out[24]:
0.8936064001824369

In [28]:
i = 0
for i in range(100):
    i += random_state.uniform()
i/100


Out[28]:
0.9972606483423683

In [ ]: