R. Natan Gestetner (Natan Piryo to Hil. Chanukah, p. 86) observes that according to the second reason, it would follow that if it would be possible to observe the relevant mitzvah for any length of time before the oppressors are able to interfere, one would be obligated to do so. He proceeds to explain along these lines the ruling of the Shulchan Arukh (O.C. 671:5) that during times of danger, one suffices with placing Chanukah candles on the [inside] table, rather than simply dismissing the mitzvah altogether.
The Ran continues his comment to assert that even when one is not obligated to sacrifice himself, he is permitted to volunteer to do so. This opinion is shared by Tosafot (Avodah Zarah, 27b, s.v. Yakhol). The Rambam, however, in his Mishneh Torah, (Hilkhot Yesodei HaTorah 5:1) explicitly excludes such an option. The Nimmukei Yosef to Sanhedrin takes a middle position, allowing voluntary martyrdom only for leaders of a generation who feel the circumstances are appropriate. (See Kessef Mishnah, Hilkhot Yesodei HaTorah 5:4. See also R. Yitzchak Ohlboim, Sh’eilat Yitzchak 3:106, and R. Ephraim Oshry, Responsa Mima’amakim 5:14.)
The Ramban, in the Milchamot Hashem to Sanhedrin, rules that it is forbidden for one to be stringent beyond the law in this matter, noting that no one ever suggested that if one takes ill on Shabbat, it is admirable piety not to violate Shabbat to save him. R. Shmuel Rozovsky (Zikhron Shmuel, 65) notes that the focus of the Ramban’s ruling is the obligation of “pikuach nefesh”. It may follow that in a situation in which there is no obligation of pikuach nefesh, but no obligatory martyrdom either, martyrdom may be volunteered. He thus suggests that this may be the position of the Ran in relation to positive commandments: martyrdom is not obligated, because of both of the reasons he lists; but there is no obligation of “pikuach nefesh, and thus one may still choose self-sacrifice.