s-leroux / fin

Set of tools for personal investment
MIT License
1 stars 0 forks source link

There is no obvious way to specify the aggregate function for the index. #32

Closed s-leroux closed 7 months ago

s-leroux commented 7 months ago

There is no obvious way to specify the aggregate function for the index.

I wonder if adding implicitly the index in select/group_by isn't an error. Maybe we can make the index reference mandatory. Would it be desirable to check that the index values are sorted in ascending order?

Working on that in https://github.com/s-leroux/fin/tree/exp/make-index-selection-explicit

Originally posted by @s-leroux in https://github.com/s-leroux/fin/issues/30#issuecomment-2043759707

Other things to consider:

s-leroux commented 7 months ago
  • OTOH, some use cases seem hard to express at first sight without explicit index selection. For example: "Calculate the average prices per month"

What about:

serie.select(
  (fc.named("MONTH"), fc.month, "DATE"),
  (fc.named("PRICE"), "CLOSE"),
).sort_by(
  (fc.concat, "MONTH", "DATE"),
).group_by(
  "MONTH",
  (ag.avg, fc.named("AVG PRICE"), "PRICE")
)

Few comments:

s-leroux commented 7 months ago

From c058cfb1523e734548d1479a90ad2f02f4406d50 and now on, I will experiment with removing the index "special" column.

Some previously implicit things will have to now become explicit, like specifying the join column(s). This will cause problems with the operator version & and |.

s-leroux commented 7 months ago

... or we may make the index a "hidden" property of the serie to keep track of their order for operations that require implicit knowledge of that?

s-leroux commented 7 months ago

... or we may make the index a "hidden" property of the serie to keep track of their order for operations that require implicit knowledge of that?

I didn't manage to achieve something satisfying. Having a "hidden" index is not such a good idea as it rapidly become confusing for the user. Hard coding the index as columns[0] was not very convincing either.