<s> """<STR_LIT>""" <EOL> import datetime <EOL> import common <EOL> from pyalgotrade . technical import linreg <EOL> from pyalgotrade import dataseries <EOL> class LeastSquaresRegressionTestCase ( common . TestCase ) : <EOL> def testLsreg1 ( self ) : <EOL> x = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> a , b = linreg . lsreg ( x , y ) <EOL> self . assertEqual ( round ( a , <NUM_LIT:2> ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( round ( b , <NUM_LIT:2> ) , <NUM_LIT:1.0> ) <EOL> def testLsreg2 ( self ) : <EOL> x = [ <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> ] <EOL> y = [ <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> ] <EOL> a , b = linreg . lsreg ( x , y ) <EOL> self . assertEqual ( round ( a , <NUM_LIT:2> ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( round ( b , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> def testLsreg3 ( self ) : <EOL> x = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> y = [ <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> ] <EOL> a , b = linreg . lsreg ( x , y ) <EOL> self . assertEqual ( round ( a , <NUM_LIT:2> ) , <NUM_LIT:1.0> ) <EOL> self . assertEqual ( round ( b , <NUM_LIT:2> ) , <NUM_LIT:0> ) <EOL> def testStraightLine ( self ) : <EOL> seqDS = dataseries . SequenceDataSeries ( ) <EOL> lsReg = linreg . LeastSquaresRegression ( seqDS , <NUM_LIT:3> ) <EOL> nextDateTime = datetime . datetime ( <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:1> ) <EOL> seqDS . appendWithDateTime ( nextDateTime , <NUM_LIT:1> ) <EOL> self . assertEqual ( lsReg [ - <NUM_LIT:1> ] , None ) <EOL> nextDateTime = nextDateTime + datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> seqDS . appendWithDateTime ( nextDateTime , <NUM_LIT:2> ) <EOL> self . assertEqual ( lsReg [ - <NUM_LIT:1> ] , None ) <EOL> nextDateTime = nextDateTime + datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> seqDS . appendWithDateTime ( nextDateTime , <NUM_LIT:3> ) <EOL> self . assertEqual ( round ( lsReg [ - <NUM_LIT:1> ] , <NUM_LIT:2> ) , <NUM_LIT:3> ) <EOL> futureDateTime = nextDateTime + datetime . timedelta ( hours = <NUM_LIT:1> ) <EOL> self . assertEqual ( round ( lsReg . getValueAt ( futureDateTime ) , <NUM_LIT:2> ) , <NUM_LIT:4> ) <EOL> futureDateTime = futureDateTime + datetime . timedelta ( minutes = <NUM_LIT:30> ) <EOL> self . assertEqual ( round ( lsReg . getValueAt ( futureDateTime ) , <NUM_LIT:2> ) , <NUM_LIT> ) <EOL> futureDateTime = futureDateTime + datetime . timedelta ( minutes = <NUM_LIT:30> ) <EOL> self . assertEqual ( round ( lsReg . getValueAt ( futureDateTime ) , <NUM_LIT:2> ) , <NUM_LIT:5> ) <EOL> nextDateTime = nextDateTime + datetime . timedelta ( milliseconds = <NUM_LIT:50> ) <EOL> seqDS . appendWithDateTime ( nextDateTime , <NUM_LIT:4> ) <EOL> nextDateTime = nextDateTime + datetime . timedelta ( milliseconds = <NUM_LIT:50> ) <EOL> seqDS . appendWithDateTime ( nextDateTime , <NUM_LIT:5> ) <EOL> self . assertEqual ( round ( lsReg [ - <NUM_LIT:1> ] , <NUM_LIT:2> ) , <NUM_LIT:5> ) </s>
