jfmatth / investing

AIM v3 investing website
1 stars 0 forks source link

Microservice - Add MS to show max move by stock #6

Open jfmatth opened 3 years ago

jfmatth commented 3 years ago

given a stock, show it's biggest downside move from day-to-day. see code below

def maximum_price_diff(pl):
    # given a pricelist PL, determine the maximum one-day drop
    # PL = [n]['date','close']
    # assume the list is in date assending order

    max_diff = {'date': None,
                'max': 0}

    for x in range(1, len(pl)):
        today = pl[x]['close']
        yesterday = pl[x-1]['close']
        diff = today - yesterday

        if diff < max_diff['max']:
            max_diff['max'] = diff
            max_diff['date'] = pl[x]['date']
            # print(pl[x]['date'], yesterday, today, max_diff)

    return(max_diff)

and then to call it...

pl = Price.objects.filter(symbol__name="SPXL").values('date','close').order_by('date')
maximum_price_diff(pl)