Suneido

Integrated Application Platform

  • Home
  • Learning
    • Suneido Manual
    • Beginners
      • Inside Suneido
      • The Suneido Programming Language
      • The Suneido Database
      • Installing Suneido
      • Building Suneido
      • IDE Go To Tour
      • Upgrading To A New Release
    • Advanced
      • Canvas Control
      • DrawControl Part 1
      • DrawControl Part 2
      • DrawControl Part 3
      • SAX Like XML Processing
      • A Plug-In Architecture
      • A Simple Wizard Framework
      • An HTML Include Facility
      • An RSS 2 Feed Creator
      • MIME Generation
      • A New Add-on Facility
      • Workspace Improvement Hack
    • Mockito for Suneido
    • The Suneido Task Scheduler
    • Contributing To Suneido
    • Contributor Assignment of Copyright
    • Language Translation
    • Future Directions
    • Interview With Andrew Mckinlay
  • Forum
    • Announcements
    • Internals & Enhancements
    • Cookbook
    • General
  • FAQ
  • Screenshots
  • Downloads
  • Links

Accessing previous record from current record

Integrated Application Platform › Forums › General › Accessing previous record from current record

  • This topic has 2 replies, 2 voices, and was last updated 10 years, 1 month ago by ajith.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • November 27, 2012 at 11:28 am #740
    ajith
    Participant

    Hello,
    I wanted to calculate exponential moving averages and few other parameters for the value of stocks. there is no real need to store the values. Howeever, the calculation involves accessing theprevious record. The key field for the table is date. Howeveer, the previous record does not mean the previous date (as stock market may not have worked on that date). Which dates to skip is also not known before hand as there are some random holidays other than weekends.
    I am currently managing by (1) adding a index column carrying a serial number and then (2) using a function built on QueryApplyMulti to calculate the values and then storing them in columns. Howeever, this will become costly in terms of computation time and storage space when the program actually runs with data of atleast a hundres stocks.
    So, I want to know
    1) Is there a way to access the previous record of the same table from a Rule for a field?
    2) If so, would it be a better option to build a rule and leave it as a calculated column rather than storing it?
    3) How do I find a record (while inside a QueryApply loop), say 10 up of my current record (when the query is sorted using the key field) ?
    4) Is there a better way to do this (say for repeatedly calculating for each row, the sum of the 10 preceeding values of the column of interest ) other than using QueryApply?
    Thanks,
    ajith

    November 30, 2012 at 4:51 pm #950
    amckinlay
    Keymaster

    1) You can get the previous record with something like:

    prev = QueryLast("mytable where date < " $ Display(currrent_date) $ " sort date")

    Note: "previous" only makes sense when you specify a sort, otherwise Suneido doesn't guarantee any particular order.

    If you wanted to get multiple previous records you could use the same query and read Prev multiple times.

    2) I would leave it as a calculated column unless speed becomes a problem.

    3) see (1)

    4) if the data is small enough (e.g. less than 10,000 records) then it may be easier to read the data into memory and work with it there. Then you do not need to do queries to get previous records.

    December 4, 2012 at 2:31 pm #951
    ajith
    Participant

    Hello,

    Thanks! I will try using calculated fields.
    ajith

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

Search Forums

Log In
Welcome to the new Suneido Web Site and Forum.
Register
Lost Password
users of the previous PHPBB Forum should be able to log in with their previous username and password.

Recent Topics

  • Alpha copy of gSuneido to play with
  • how to start jsuneido ?
  • Problem Starting Suneido…
  • Dialog not showing buttons
  • New link for Suneidojo

Contact Us | Legal Statement | Privacy Statement | SiteMap

Copyright © 2023 Axon® Development Corporation. All Rights Reserved. - Open Source Integrated Database and Programming Language