Google Groups Home
Help | Sign in
Making predictions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  6 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
gosi  
View profile
 More options Jan 3, 11:37 am
From: gosi <gos...@gmail.com>
Date: Thu, 3 Jan 2008 08:37:04 -0800 (PST)
Local: Thurs, Jan 3 2008 11:37 am
Subject: Making predictions

Making predictions about the future can be fun.
If you have some data to work with it can be fun
to fit some curves to the data and then use those
curves to create a few points into the future.

J has some built in utilities that can be of use to make
predictions.

So be requiring statfns to be able to use the lsfit verb.
In order to look at the results it can be good to require plot
as well.

require'plot statfns'

In order to make it easy to call the verb I create one that
takes both left and right arguments and call it spa.

spa=: 4 : 0

starts the editor to get in new lines to a verb with arguments
on both sides.

The right argument will be containing the data for the verb.
I take the number of numbers coming in and create x1 to contain
a list of x values for those data values.

x1=. i.#y

I prepare the right argument for lsfit and create dat

dat=. x1,:y

The left agument of spa will give me the number of points I
want to extend the curves and give me predictions and create
a new list x2 to hold all the x1 values and add extra numbers
at the end

x2=.x1,({:x1)+1+i.x

I am now ready to make predicions and call lsfit and store the
results in y1 to y5

y1=. (1 lsfit dat) p. x2

I want to create a plot and use the pd commands

pd 'new'

And then put some text on the plot and use symbol for
the original data

pd 'title Spa i framtidina'
pd 'backcolor lightgray'
pd 'type symbol'

It is now time to create the original plot

pd   x1;y

Then use line for the curves

pd 'type line'
pd   x2;y1,y2,y3,y4,:y5

And the I want to lok at what the plot looks like

pd 'show'

)

A right paranthesis at the end will en the verb and it is ready
to use

3 spa 1 2 3 4 2 5 2 11

Calls spa and asks for 3 points prediction and gives the list
1 2 3 4 2 5 2 11 as data

Hmmmmm.....

This plot is a bit crowded with all these curves at the same
time.

I use this verb and take copy and create a new verb spall
and add an extra parameter that allows me to get the curves
one at a time.

I will call spall with the same right argument but I add extra
argument to x on the left.

I use x3 to replace the original x and create a new x4 to choose
the plots.

x3=.>{.x
x4=.0+{.>}.x

I then use x4 in a new select and case section

select. x4
  case. 1 do.  pd x2;y1

So if x4 is one I get a plot with only the results from
1 lsfit and so on.

Calling spall like

(3;1) spall 1 2 3 4 2 5 2 11 55 22 11

will select that case

The other cases come similarly

(3;2) spall 1 2 3 4 2 5 2 11 55 22 11
(3;3) spall 1 2 3 4 2 5 2 11 55 22 11
(3;4) spall 1 2 3 4 2 5 2 11 55 22 11
(3;5) spall 1 2 3 4 2 5 2 11 55 22 11
(3;6) spall 1 2 3 4 2 5 2 11 55 22 11

If I want more points predicted

(13;1) spall 1 2 3 4 2 5 2 11 55 22 11

Would give me 13 points instead 3 in the earlier examples.

-----------------------  all the script follows here

require'plot statfns'

spa=: 4 : 0
x1=. i.#y
dat=. x1,:y
x2=.x1,({:x1)+1+i.x
y1=. (1 lsfit dat) p. x2
y2=. (2 lsfit dat) p. x2
y3=. (3 lsfit dat) p. x2
y4=. (4 lsfit dat) p. x2
y5=. (5 lsfit dat) p. x2
pd 'new'
pd 'title Spa i framtidina'
pd 'backcolor lightgray'
pd 'type symbol'
pd   x1;y
pd 'type line'
pd   x2;y1,y2,y3,y4,:y5
pd 'show'
)

3 spa 1 2 3 4 2 5 2 11

spall=: 4 : 0
x3=.>{.x
x4=.0+{.>}.x
x1=. i.#y
dat=. x1,:y
x2=.x1,({:x1)+1+i.x3
y1=. (1 lsfit dat) p. x2
y2=. (2 lsfit dat) p. x2
y3=. (3 lsfit dat) p. x2
y4=. (4 lsfit dat) p. x2
y5=. (5 lsfit dat) p. x2
pd 'new'
pd 'title Spa i framtidina'
pd 'backcolor lightgray'
pd 'type symbol'
pd   x1;y
pd 'type line'
select. x4
  case. 1 do.  pd x2;y1
  case. 2 do.  pd x2;y2
  case. 3 do.  pd x2;y3
  case. 4 do.  pd x2;y4
  case. 5 do.  pd x2;y5
  case. 6 do.  pd x2;y1,y2,y3,y4,:y5
end.
pd 'show'
)

(3;1) spall 1 2 3 4 2 5 2 11 55 22 11
(3;2) spall 1 2 3 4 2 5 2 11 55 22 11
(3;3) spall 1 2 3 4 2 5 2 11 55 22 11
(3;4) spall 1 2 3 4 2 5 2 11 55 22 11
(3;5) spall 1 2 3 4 2 5 2 11 55 22 11
(3;6) spall 1 2 3 4 2 5 2 11 55 22 11

(13;1) spall 1 2 3 4 2 5 2 11 55 22 11


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gosi  
View profile
 More options Jan 10, 8:20 am
From: gosi <gos...@gmail.com>
Date: Thu, 10 Jan 2008 05:20:57 -0800 (PST)
Local: Thurs, Jan 10 2008 8:20 am
Subject: Re: Making predictions

From the page about the price of oil
http://oilnergy.com/1opost.htm

I read in the points from the yearly prices

a=:30 22 21 20 20 22 23 21 21 21 21 15 16 15 19 19 19 18 19 19 19 20
20 19 19 20 20 20 20 22 25 30 30 30 30 31 32 31 31 32 32 32 33 35 35
35 35 35 36 36 36 36 38 36 36 36 36 36 36 36 36 36 37 37 37 37 37 38
38 39 39 40 75 78 80 52 90 140 220 320 310 305 290 130 155 130 160 200
170 165 148 140 149 180 168 110 160 270 230 240 280 370

a will then contain data until 2005 since 1920

   (3;1) spall a

The older data may not be so interesting for the predictions so I take
the last 30 years since 1975
   (3;1) spall _30{.a

I try out different options and find the 3 gives good fit

   (3;3) spall _30{.a

It gives quite a good fit and the two more points available fit well
into the estimate

I then add the two remaining actual points in

b=: a,500 600

   (3;3) spall _30{.b

Whatever option I use then for the foreseeable future it looks like
the prices of oil are going up


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Lynn & Bob Graf  
View profile
 More options Jan 10, 9:28 am
From: Lynn & Bob Graf <lbg...@yahoo.com>
Date: Thu, 10 Jan 2008 06:28:31 -0800 (PST)
Local: Thurs, Jan 10 2008 9:28 am
Subject: Re: Making predictions

Do you really believe that oil prices can be extrapolated into the future based on historical pricing data alone?  Incredible!  I daresay that without being able to factor in issues of international politics, future value of currencies and possibly gold, technical inovation, mass psychology, among other things, this whole prediction business is no more than a mathematical curiosity.  If it's really relevant, perhaps you should be publishing this stuff elsewhere....  

What is being done here seems to a person like me with no economics knowledge, as the equivalent of trying to fit any data to a  polynomial equation.  That works well for interpolation, but for extrapolation - you've got to be kidding.  The equations used to fit data for extrapolation must be based on scientific reality, which usually results in a non-linear regression analysis using something like a Marquardt algorithm to an equation which can be virtually anything depending on discipline.  Considering that economics is, I believe, at best, a soft science, and validity to this prediction would be dumb luck.

gosi <gos...@gmail.com> wrote:

From the page about the price of oil
http://oilnergy.com/1opost.htm

I read in the points from the yearly prices

a=:30 22 21 20 20 22 23 21 21 21 21 15 16 15 19 19 19 18 19 19 19 20
20 19 19 20 20 20 20 22 25 30 30 30 30 31 32 31 31 32 32 32 33 35 35
35 35 35 36 36 36 36 38 36 36 36 36 36 36 36 36 36 37 37 37 37 37 38
38 39 39 40 75 78 80 52 90 140 220 320 310 305 290 130 155 130 160 200
170 165 148 140 149 180 168 110 160 270 230 240 280 370

a will then contain data until 2005 since 1920

   (3;1) spall a

The older data may not be so interesting for the predictions so I take
the last 30 years since 1975
   (3;1) spall _30{.a

I try out different options and find the 3 gives good fit

   (3;3) spall _30{.a

It gives quite a good fit and the two more points available fit well
into the estimate

I then add the two remaining actual points in

b=: a,500 600

   (3;3) spall _30{.b

Whatever option I use then for the foreseeable future it looks like
the prices of oil are going up

---------------------------------
Never miss a thing.   Make Yahoo your homepage.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
DevonMcC@gmail.com  
View profile
 More options Jan 10, 10:04 am
From: "Devon...@gmail.com" <Devon...@gmail.com>
Date: Thu, 10 Jan 2008 07:04:01 -0800 (PST)
Local: Thurs, Jan 10 2008 10:04 am
Subject: Re: Making predictions
Actually, future oil prices can be extrapolated on even less data: the
supply is finite and consumption is growing.

However, Gosi's exercise here is a nice example of using J to simply
apply a moderately sophisticated technique to a price series and
display the result graphically.  To take this a little further, I
would suggest a few enhancements.

1. Use better names - for instance, instead of "a", how about
something like "oilpx" ("px" is a common abbreviation for "price")?
2. Combine better names with some J shortcuts for breaking apart
data.  For instance, "x3" and "x4" could be assigned with a statement
like
   'polydegree fittype'=. x  NB. Assuming my guesses about meaning of
these 2 vars are correct...
3. Show the original data in the same picture as the fitted line.

Also, I might not bother with the intermediate variables y1 through y5
- their values could be calculated in-line just as easily, but that's
a matter of taste.

As to the validity of forecasting this way, I have a library of more
than a hundred books about this subject and have been studying it for
years, so it's far too involved to get into here.  Suffice to say that
this is a good pedagogical example.

On Jan 10, 9:28 am, Lynn & Bob Graf <lbg...@yahoo.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gosi  
View profile
 More options Jan 11, 4:34 am
From: gosi <gos...@gmail.com>
Date: Fri, 11 Jan 2008 01:34:17 -0800 (PST)
Local: Fri, Jan 11 2008 4:34 am
Subject: Re: Making predictions
I once saw a method of giving the data less and less weight the older
it got.
I think it was called Browne's method but can not find it.

It is quite obvious that very old price of oil does not add much to
mathematical prediction.
There are so many other factors that play into it.
On the page I picked the data from they only use 1 lsfit and that does
not do much for the data.
Most of the time higher number to the left of lsfit gives better fit.

I think this kind of extrapolating is not worse than just put your
finger up and make a guess.
And 5 lsfit predicted many years into the futures shows the oil prices
going down eventually --- who knows!

Anyway I am more after showing J in action than guessing where the oil
is going.

On Jan 10, 3:04 pm, "Devon...@gmail.com" <Devon...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
gosi  
View profile
 More options Feb 12, 9:22 am
From: gosi <gos...@gmail.com>
Date: Tue, 12 Feb 2008 06:22:46 -0800 (PST)
Local: Tues, Feb 12 2008 9:22 am
Subject: Re: Making predictions

On Jan 10, 3:04 pm, "Devon...@gmail.com" <Devon...@gmail.com> wrote:

> However, Gosi's exercise here is a nice example of using J to simply
> apply a moderately sophisticated technique to a price series and
> display the result graphically.  

I placed a file to the group.
I have not tried that before so it would be interesting to hear if you
can download it.

The file is a J script.

If you run the script it shows a few plots.

Up in the left corner is a field to edit.
Type in a value and press the button next to it.

What it does is place an order to a store and the store - verzlun -
will automatically place an order to the next instance - a whole
saler.
The wole saler - heild - will in turn place and order to framl which
in turn makes an order from the factory - verk.

The orders use spa1 a verb that makes one guess about the future based
on the data on the left.

The button down to the left gives the left argument to spa1 - 1 to 5

The plots in the top row give the orders.
The middle row gives the lager status.
The lowes row gives the status of shortage.

spa1 gives lowest 0 as an order.

It is interesting to give as an input something like 11 a few times
like 10 times or so - counter top left.
Then send in 111 a few times like 10 more times.
Then lower the input to 11 again a few times and then see the
difference what the various predictions make on the others.


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2008 Google