我有一些值amt1, amt2
和val1 = .75, val2 = 1.25
。我想做这样的事情:
说amt1
为1000,我乘以val1
1000 * .75 = 750,然后将该金额分配给amt2
,amt2 = amt1 * val1
。
然后我将amt2
乘以val2
,所以750 * 1.25 = 937。
如果amt2 * val2
的乘积小于amt1
,则再次执行整个计算,直到val2
具有导致总和大于amt1
的值。
我还想要它,如果它确实等于然后再做整个事情,但是反转的值有点像这样。我真的不确定如何实现这个,甚至不知道如何正确地提出问题。
# -*- coding: utf-8 -*-
"""
Created on Sun Jul 23 00:57:28 2017
@author: Anwar Goulouh
"""
def infiniteloop():
# TRADE1
# define an amount to trade first myAmt1, define what base currency is
# and currency to trade to nzd and usd, define exchange rates for both,
# once i have completed the second trade I would like to do trade 1 again
# only the myAmt1 will be the value in myResult2
myAmt1 = int(10000)
print ("My Amount 1 = $",myAmt1)
myVar1 = "nzd"
myVar2 = "usd"
# Iwould like these following two values to be either a webrequest from
# google or random decimals for myVar1ExRate value will always be 1 an the
# second will be something between 0.701 and 0.909 so need to figure out
# how to generate the random number also for now i will use hardcoded
# values
myVar1ExRate = int(1.00)
myVar2ExRate = float(0.7565)
print ("ex rates", myVar1,myVar2,"NZD ExRate =", myVar1ExRate,"USD ExRate
=",myVar2ExRate,)
# do first trade
print ("do first trade $",myAmt1, "* USD Ex Rate",myVar2ExRate,)
myAmt2 = int(myAmt1*myVar2ExRate)
print ("My Amount 2 =$",myAmt2)
# TRADE2
# I then attempt to trade the full amount of myAmt2 back from USD to NZD
# and make a profit to do this the
# the exchange rate of the NZD must be above a certain amount otherwise
# it will result in a loss i do not know how to correctly code the if
# statement for this but will make an attempt the idea is that it runs
# infinitely.
# So...
# I then switch the values of myVar1 and my Var2 as follows and put them
# to new vars so I can use them again i also need to define the previous
# amount of MyAmt1
myVar1Prev = (myVar1)
myVar2Prev = (myVar2)
myAmt1Prev = (myAmt1)
# I now perform the switch
myVar1 = (myVar2Prev)
myVar2 = (myVar1Prev)
print ("New currencies", myVar1, myVar2)
# add the new exchange rates
myNewExRate1 = int(1)
myNewExRate2 = float(1.2523)
print ("New ex rates", myVar1,myVar2,"USD ExRate =", myNewExRate1,"NZD
ExRate =",myNewExRate2,)
# now i need to do an if statement and if it fails then try again until
# MyNewExRate2 has a value which equals a profit
if myAmt1Prev == (myAmt1Prev < myAmt2 * myNewExRate2):
myNewAmt2 = int(myAmt1Prev < myAmt2 * myNewExRate2)
print ("the Amount is less than$", myAmt1Prev)
else
myAmt1Prev == (myAmt1Prev > myAmt2 * myNewExRate2):
myNewAmt2 = int(myAmt1Prev > myAmt2 * myNewExRate2)
print ("you made a profit$", myAmt1Prev)
# once this is all done say if myNewExrate had been 1.4565 and i had
# successfully made a profit I want to then put the new amount I had made
# in the else statement to myAmt1 then do the if statement again to see if
# i would make a profit trading back to USD and so on forever
# I should be able to get this to run infinitely but am unsure how to code
# it effeciently and correctly I dont know?????
infiniteloop()